package com.fowo.api.ptt.controller;

import com.fowo.api.common.model.R;
import com.fowo.api.ptt.enitty.PrintTemplateGroup;
import com.fowo.api.ptt.service.PrintTemplateGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 打印组控制器
 * @author yl_ls
 */
@Tag(name = "PrintTemplateGroup", description = "打印组")
@RestController
@RequestMapping("api/sys/print-template-group")
public class PrintTemplateGroupController {

    @Resource
    private PrintTemplateGroupService printTemplateGroupService;


    @Operation(summary = "创建组")
    @PreAuthorize("@am.canAccess('printTemplateGroupCreate')")
    @PostMapping
    public R<?> create(@RequestBody PrintTemplateGroup printTemplateGroup) {
        return R.data(() -> printTemplateGroupService.create(printTemplateGroup));
    }

    @Operation(summary = "更新组")
    @PreAuthorize("@am.canAccess('printTemplateGroupUpdate')")
    @PutMapping
    public R<?> update(@RequestBody PrintTemplateGroup printTemplateGroup) {
        return R.run(() -> printTemplateGroupService.update(printTemplateGroup));
    }

    @Operation(summary = "删除组")
    @PreAuthorize("@am.canAccess('printTemplateGroupDelete')")
    @DeleteMapping("{id}")
    public R<?> delete(@PathVariable Long id) {
        return R.run(() -> printTemplateGroupService.delete(id));
    }
}
